<?
include('inc_security.php');

$type       = getValue('type', 'str', 'GET', '');
$record_id  = getValue('record_id');
$redirect   = getValue('redirect', 'str', 'GET', base64_encode('listing.php'));

$db_check = new db_query('SELECT ' . $id_field . ',' . $gs_fieldupload . ' FROM ' . $gs_table . ' WHERE ' . $id_field . ' = ' . $record_id . ' AND lang_id = ' . $lang_id);
if ($check = mysql_fetch_assoc($db_check->result))
{
	if ($type == "")
	{
		if (checkDeleteBrand($record_id))
		{
			if($check[$gs_fieldupload] != "") delete_file($gs_filepath, $check[$gs_fieldupload]);
			// Xoa data
			$db_delete = new db_execute('DELETE FROM ' . $gs_table . ' WHERE ' . $id_field . ' = ' . $record_id . ' AND lang_id = ' . $lang_id);
			unset($db_delete);
		}
		else
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
			echo '<script language="javascript">alert("Thương hiệu này đã có dữ liệu. Bạn hãy xóa dữ liệu trước rồi thử lại.")</script>';
		}
	}
	else
	{
		if($check[$gs_fieldupload] != "") delete_file($gs_filepath, $check[$gs_fieldupload]);
		$query_str = "UPDATE " . $gs_table . " SET " . $gs_fieldupload . " = NULL WHERE " . $id_field . " = " . $record_id;
		$db_execute = new db_execute($query_str);
		unset($db_execute);
	}
}
unset($db_check);
redirect(base64_decode($redirect));
?>